User = require '../models/user'
pusher = require '../robots/pusher'
async = require 'async'
module.exports = 
	'get /user': (req, res)->
		User.findAll().success (user)->
			res.send user


	'post /push/:id': (req, res)->
		user = req.body
		pusher.send user.fakeid, user.content, (err)->
			res.send 200, err

	'get /user/sync': (req, res)->
		pusher.getFans 0,(err,fans)->
			console.log err
			console.log fans
			async.forEachSeries fans, (fan,cb)->
				user = 
					name:fan.nick_name
					fakeid:fan.id
				User.build(user).save()
				.success  (user)-> 
					cb null
				.error (err)->
					console.log err
					cb null
			,(err)->
				res.send 200,err